package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.api.RemoteProductService;
import com.sikaryofficial.system.api.model.ip.IpLocationVO;
import com.sikaryofficial.system.api.model.product.ProductStatisticsReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 日志服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);

    @Override
    public RemoteProductService create(Throwable throwable) {

        log.error("自动处理未生成系统产品的二维码调用失败:{}", throwable.getMessage());
        return new RemoteProductService() {
            /**
             * 自动处理处理获奖邮件发送
             *
             * @return 结果
             */
            @Override
            public R<Boolean> autoSendAwardsEmailNotice() {
                return R.fail("自动处理处理获奖邮件发送失败:" + throwable.getMessage());
            }

            /**
             * 二维码扫描统计更新
             *
             * @param req
             * @return
             */
            @Override
            public R<Boolean> normalSave(ProductStatisticsReq req) {
                return R.fail("二维码扫描统计更新失败:" + throwable.getMessage());
            }

            /**
             * 通过IP获取国家、区域、城市数据
             *
             * @param ip 输入IP
             * @return
             */
            @Override
            public R<IpLocationVO> getCountryArea(String ip) {
                return R.fail("通过IP获取国家、区域、城市数据失败:" + throwable.getMessage());
            }
        };
    }
}
